//
//  CARegisteredVC.m
//  CleanerAir_Project
//
//  Created by 付亚杰 on 16/6/6.
//  Copyright © 2016年 Beijing Colin El Internet. All rights reserved.
//

#import "CARegisteredVC.h"
#import "CAMerchantsRegisteredVC.h"
#import "CAIndividualBusinessesVC.h"

typedef enum {
    
    PERSONAL = 0,//个人商户
    THE_MAll = 1//商场商户
    
}MerchantsTypes;

@interface CARegisteredVC ()<UITextFieldDelegate>{

    MerchantsTypes _merchantsTypes;

}

@property (weak, nonatomic) IBOutlet UIView *myView;

@property (weak, nonatomic) IBOutlet UISegmentedControl *segmentedCon;

@property (weak, nonatomic) IBOutlet UITextField *InviteCode;

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@end

@implementation CARegisteredVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"选择商户类型";
    
    self.InviteCode.delegate = self;
    
    [self.InviteCode.layer setMasksToBounds:YES];
    [self.InviteCode.layer setBorderWidth:0.5];
    [self.InviteCode.layer setBorderColor:[[UIColor colorWithRed:190.0/255.0 green:190.0/255.0 blue:190.0/255.0 alpha:1] CGColor]];
    
    [self.myView.layer setMasksToBounds:YES];
    [self.myView.layer setBorderWidth:0.5];
    [self.myView.layer setBorderColor:[[UIColor colorWithRed:99.0/255.0 green:166.0/255.0 blue:242.0/255.0 alpha:1] CGColor]];
    
    _merchantsTypes = THE_MAll;
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)nextClick:(id)sender {
    
    if([self.InviteCode.text isEqualToString:@""]){
        [ShowMessage showCenterViewMessage:_merchantsTypes == PERSONAL ? @"请输入MAX码" : @"请输入邀请码"];
        return;
    }
    
    NSString *iCode = self.InviteCode.text;
    
    switch (_merchantsTypes) {
        case PERSONAL:{
            
            CAMerchantsRegisteredVC *merchants = [[CAMerchantsRegisteredVC alloc] init];
            merchants.code = iCode;
            merchants.registerType = INDIVIDUAL_BUSINESSES;
            
            self.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:merchants animated:YES];
            
            break;
        }
        case THE_MAll:{
            
            CAMerchantsRegisteredVC *merchants = [[CAMerchantsRegisteredVC alloc] init];
            merchants.code = iCode;
            merchants.registerType = MALL_MERCHANTS;
            self.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:merchants animated:YES];
            
            break;
        }
            
        default:
            break;
    }
    
}

- (IBAction)segmentedClick:(UISegmentedControl *)sender {
    
    NSInteger index = sender.selectedSegmentIndex;
    
    switch (index) {
        case 0:{
            
            _merchantsTypes = PERSONAL;
            
            self.titleLabel.text = @"请输入空气净化器机器的MAX码";
            
            break;
        }
        case 1:{
         
            _merchantsTypes = THE_MAll;
            
            self.titleLabel.text = @"请输入商家注册邀请码";
            
            break;
        }
        default:
            break;
    }
}

#pragma mark -- UITextFiledDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.view endEditing:YES];
    [self nextClick:nil];
    return YES;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
